/**
 */
package de.hwrberlin.remo.model.impl;

import de.hwrberlin.remo.model.Fact;
import de.hwrberlin.remo.model.KnowledgeBaseElement;
import de.hwrberlin.remo.model.LinksFromFacts;
import de.hwrberlin.remo.model.RemoModelPackage;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EcoreUtil;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Links From Facts</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link de.hwrberlin.remo.model.impl.LinksFromFactsImpl#getElement <em>Element</em>}</li>
 *   <li>{@link de.hwrberlin.remo.model.impl.LinksFromFactsImpl#getFact <em>Fact</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class LinksFromFactsImpl extends LinkObjectImpl implements LinksFromFacts {
	/**
	 * The cached value of the '{@link #getElement() <em>Element</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getElement()
	 * @generated
	 * @ordered
	 */
	protected KnowledgeBaseElement element;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected LinksFromFactsImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return RemoModelPackage.Literals.LINKS_FROM_FACTS;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public KnowledgeBaseElement getElement() {
		if (element != null && element.eIsProxy()) {
			InternalEObject oldElement = (InternalEObject)element;
			element = (KnowledgeBaseElement)eResolveProxy(oldElement);
			if (element != oldElement) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, RemoModelPackage.LINKS_FROM_FACTS__ELEMENT, oldElement, element));
			}
		}
		return element;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public KnowledgeBaseElement basicGetElement() {
		return element;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetElement(KnowledgeBaseElement newElement, NotificationChain msgs) {
		KnowledgeBaseElement oldElement = element;
		element = newElement;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, RemoModelPackage.LINKS_FROM_FACTS__ELEMENT, oldElement, newElement);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setElement(KnowledgeBaseElement newElement) {
		if (newElement != element) {
			NotificationChain msgs = null;
			if (element != null)
				msgs = ((InternalEObject)element).eInverseRemove(this, RemoModelPackage.KNOWLEDGE_BASE_ELEMENT__RELATEDLINKEDFACTS, KnowledgeBaseElement.class, msgs);
			if (newElement != null)
				msgs = ((InternalEObject)newElement).eInverseAdd(this, RemoModelPackage.KNOWLEDGE_BASE_ELEMENT__RELATEDLINKEDFACTS, KnowledgeBaseElement.class, msgs);
			msgs = basicSetElement(newElement, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, RemoModelPackage.LINKS_FROM_FACTS__ELEMENT, newElement, newElement));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Fact getFact() {
		if (eContainerFeatureID() != RemoModelPackage.LINKS_FROM_FACTS__FACT) return null;
		return (Fact)eInternalContainer();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetFact(Fact newFact, NotificationChain msgs) {
		msgs = eBasicSetContainer((InternalEObject)newFact, RemoModelPackage.LINKS_FROM_FACTS__FACT, msgs);
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setFact(Fact newFact) {
		if (newFact != eInternalContainer() || (eContainerFeatureID() != RemoModelPackage.LINKS_FROM_FACTS__FACT && newFact != null)) {
			if (EcoreUtil.isAncestor(this, newFact))
				throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
			NotificationChain msgs = null;
			if (eInternalContainer() != null)
				msgs = eBasicRemoveFromContainer(msgs);
			if (newFact != null)
				msgs = ((InternalEObject)newFact).eInverseAdd(this, RemoModelPackage.FACT__LINKSFACTS, Fact.class, msgs);
			msgs = basicSetFact(newFact, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, RemoModelPackage.LINKS_FROM_FACTS__FACT, newFact, newFact));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case RemoModelPackage.LINKS_FROM_FACTS__ELEMENT:
				if (element != null)
					msgs = ((InternalEObject)element).eInverseRemove(this, RemoModelPackage.KNOWLEDGE_BASE_ELEMENT__RELATEDLINKEDFACTS, KnowledgeBaseElement.class, msgs);
				return basicSetElement((KnowledgeBaseElement)otherEnd, msgs);
			case RemoModelPackage.LINKS_FROM_FACTS__FACT:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetFact((Fact)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case RemoModelPackage.LINKS_FROM_FACTS__ELEMENT:
				return basicSetElement(null, msgs);
			case RemoModelPackage.LINKS_FROM_FACTS__FACT:
				return basicSetFact(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
		switch (eContainerFeatureID()) {
			case RemoModelPackage.LINKS_FROM_FACTS__FACT:
				return eInternalContainer().eInverseRemove(this, RemoModelPackage.FACT__LINKSFACTS, Fact.class, msgs);
		}
		return super.eBasicRemoveFromContainerFeature(msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case RemoModelPackage.LINKS_FROM_FACTS__ELEMENT:
				if (resolve) return getElement();
				return basicGetElement();
			case RemoModelPackage.LINKS_FROM_FACTS__FACT:
				return getFact();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case RemoModelPackage.LINKS_FROM_FACTS__ELEMENT:
				setElement((KnowledgeBaseElement)newValue);
				return;
			case RemoModelPackage.LINKS_FROM_FACTS__FACT:
				setFact((Fact)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case RemoModelPackage.LINKS_FROM_FACTS__ELEMENT:
				setElement((KnowledgeBaseElement)null);
				return;
			case RemoModelPackage.LINKS_FROM_FACTS__FACT:
				setFact((Fact)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case RemoModelPackage.LINKS_FROM_FACTS__ELEMENT:
				return element != null;
			case RemoModelPackage.LINKS_FROM_FACTS__FACT:
				return getFact() != null;
		}
		return super.eIsSet(featureID);
	}

} //LinksFromFactsImpl
